package com.hz.house.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hz.house.bean.entity.CustomerBean;
import com.hz.house.bean.entity.SellManScoreBean;
import com.hz.house.bean.vo.ConsumerCallTemplateMsg;
import com.hz.house.bean.vo.SellManTemplateMsg;
import com.hz.house.bean.vo.SimpleTemplateMsgBean;
import com.hz.house.common.ThreadPool;
import com.hz.house.dao.CustomerMapper;
import com.hz.house.enums.SellManScoreEnum;
import com.hz.house.utils.DaysIntUtil;
import com.hz.house.utils.wxutil.WXPayUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.*;

@Service
@Slf4j
public class WxgzhSellHouseService {

	@Resource
	private RestTemplate restTemplate;

	@Autowired
	private CustomerMapper customerMapper;

	@Autowired
	private SellManScoreService sellManScoreService;

	@Autowired
	private ThreadPool threadPool;

	@Autowired
	private RedisCacheDataService redisCacheDataService;

	private static final String WXGZH_SELL_APPID = "wx8aab5c1fc9f0236b";

	private static final String WXGZH_SELL_SK = "0725f3f682bfa42e41b6cb4ff6fbf154";

	/**
	 * 成都卖房帮手IM消息模板
	 */
	private static final String TEMPLATEMSG_ZIXUN_ID = "35GLThNocp9bgxLhhEgs6dPNc1eqnjXSGapV-GiR8xE";

	/**
	 * 成都卖房帮手电话咨询消息模板
	 */
	private static final String TEMPLATE_CALL_ID = "D7UJsJ_5g2ydLoBAXFbI9iaxGFHmjIZJBc7vutcR_8I";

	/**
	 * 成都卖房帮手积分变动通知Score
	 */
	private static final String SCORE_CHANGE = "D7UJsJ_5g2ydLoBAXFbI9iaxGFHmjIZJBc7vutcR_8I";

	/**
	 * token验证，绑定接口
	 * @return
	 */
	public String validateToken(HttpServletRequest req) {
		String echostr = req.getParameter("echostr");
		return echostr;

	}
	
	
	/**
	 * <p> 成都买房帮手微信公众服务号消息推送回调接口
	 * @param req
	 * @param rep
	 */
	public void sellHouseWxgzhCallBack(HttpServletRequest req, HttpServletResponse rep) {
		log.info("接收到卖房好帮手微信公众号消息推送");
		try {
			InputStream is = req.getInputStream();
			byte[] body = IOUtils.toByteArray(is);
			Map<String, String> m = WXPayUtil.xmlToMap(new String(body, "utf-8"));
			log.info(JSON.toJSONString(m));
			String msgType = m.get("MsgType");
			// 分发事件
			if (msgType.equals("text"))
				handleTextMsg(m);
			else if (msgType.equals("event"))
				handleEventMsg(m);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 处理用户回复的文本消息
	 * 
	 * @param param
	 */
	private void handleTextMsg(Map<String, String> param) {
		
		String content = param.get("Content");
		if(StringUtils.isEmpty(content)) {
			log.info("用户发送文本消息内无内容!");
			return;
		}
		
		switch(content) {
			 case "6":	//圣诞活动
				handleChristmasActivity(param);
				break;
				default:
					log.info("未知的文本内容:"+content);
		}
			
		
	}
	
	/**
	 * 	圣诞活动
	 * @param param
	 */
	private LocalDateTime limit = LocalDateTime.of(2019, 12,28, 0, 0);
	private void handleChristmasActivity(Map<String, String> param) {
		//到27号截至
		LocalDateTime now = LocalDateTime.now();
		if(now.isAfter(limit)) {
			log.info("时间超过27号晚上24点");
			return;
		}
		String openId = param.get("FromUserName");
		Map<String,Object> m = new HashMap<>();
		m.put("touser", openId);
		m.put("msgtype", "image");
		Map<String,Object> x = new HashMap<>();
		x.put("media_id", "St3wQ3ovJNuMJCYnNatEBaw5NzuJ7zMyFRtxdCmRQFE");
		m.put("image", x);
		String json = JSON.toJSONString(m);
		String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send"
				+ "?access_token="+getWxgzhSellhouseAcctk();
		String res = doPostSendMsg(json,url);
		System.out.println("发送圣诞抽奖海报结果:"+res);
		 
		//发送提示语
		m.clear();
		m.put("touser", openId);
		m.put("msgtype", "text");
		x.clear();
		String content = "参与圣诞免费吃牛排抽奖活动，\r\n" + 
				"具体操作如下\r\n" + 
				"1）长按图片识别二维码，进入活动页面，点击“参与抽奖”。按钮\r\n" + 
				"2）12月25日11:30，抽奖结果将通过微信消息通知，请留意微信消息提醒。\r\n" + 
				"本活动仅针对入驻了买房好帮手小程序的置业顾问参加，非入驻的置业顾问中奖无效。";
		x.put("content", content);
		m.put("text", x);
		String data = JSON.toJSONString(m);
		res = this.doPostSendMsg(data, url);
		log.info("发送用圣诞节活动指引文字：" + res);
	}
	

	/**
	 * 处理各种事件消息
	 * 
	 * @param param
	 */
	private void handleEventMsg(Map<String, String> param) {
		String event = param.get("Event");
		if (event == null)
			return;
		switch (event) {
		case "subscribe":
			handleSubscribeEvent(param);
			break;
		case "CLICK":
			handleClickEvent(param);
			break;
		case "SCAN"://扫码事件
			handleScanEvent(param, false);
			break;
		default:
			log.info("未知的事件类型:" + event);

		}

	}

	/**
	 * 处理扫码事件
	 * @param param
	 * @param fromSubscribe 是否是关注时扫码的
	 */
	private void handleScanEvent(Map<String, String> param,boolean fromSubscribe) {
		String ek = getEventKeyFromScan(param, fromSubscribe);
		switch(ek) {
			case "aritcle_year_2019"://2019年度置业顾问奖项活动，推送文章和文字内容
				handle2019SellManActivity(param);
				break;
			case "year_2019_ward1"://颁奖二维码
				 //霸占首页 财大气粗
				handle2019SellManWard(param, new String[] {"St3wQ3ovJNuMJCYnNatEBUc8eZp9LYSacpyCZVj59Ig",
						"St3wQ3ovJNuMJCYnNatEBUgnEaCPHg0B_odCDPmNask"});
				break;
			case "year_2019_ward2":
				//浏览量 优质数据提供
				handle2019SellManWard(param, new String[] {"St3wQ3ovJNuMJCYnNatEBS0DqEJI1bxON2NH7kpWpGg",
				"St3wQ3ovJNuMJCYnNatEBSortiHVuZY4vDkz4T_sUxs"});
				break;
			case "year_2019_ward3":
				//最投缘楼盘
				handle2019SellManWard(param, new String[] {"St3wQ3ovJNuMJCYnNatEBQEqO0yx17v6MGxV6r5bP14"});
				break;
			case "year_2019_ward4":
				//进步新人  最具投资眼光
				handle2019SellManWard(param, new String[] {"St3wQ3ovJNuMJCYnNatEBU8pXbOYFz0_fuXfqMWYsR8",
						"St3wQ3ovJNuMJCYnNatEBQyOQBsxbQouriDQoTIQMaU"});
				break;
			case "year_2019_ward5":
				//勤奋拓客  最受喜爱
				handle2019SellManWard(param, new String[] {"St3wQ3ovJNuMJCYnNatEBcxNp6fxxXSgaiLbYWMaFR4",
				"St3wQ3ovJNuMJCYnNatEBZNuimhLBtkrFup3iCUWYzY"});
				break;
			default:
				log.info("未知的扫码事件key:"+ek);
		
		}
	}
	
	
	private void handle2019SellManWard(Map<String, String> param,String[] imgs) {
		
		this.threadPool.runInThreadPool(()->{
			//发送文档
			this.sendTextMsg(param, 
					"此刻我和您一样，怀着激动的心情，想知晓获奖情况！！\r\n"
					+"\r\n"+
					"请点击下图↓↓↓↓，看幸运儿是不是你！");
			//发送海报
			for(String img:imgs) {
				this.sendImgMsg(param, img);
			}
		});
		
	}
	
	
	/**
	 * 处理2019年度置业顾问活动，发送文章和文案
	 * @param param
	 */
	private void handle2019SellManActivity(Map<String, String> param) {
		this.threadPool.runInThreadPool(()->{
			sendTextMsg(param, 
					"恭候大驾！\r\n"
					+ "\r\n"
					+ "欢迎您参加买房好帮手2019置业顾问年度盛典！\r\n"
					+ "\r\n"
					+ "请点击下方文章，移步主会场↓↓↓↓");
			handleNewsMsg(param,
					"置业顾问年终庆典|你是2019最亮的“星”",
					"感谢有你，风雨同舟", 
					"https://housessmall-dev-index-img-1258778894.cos.ap-chengdu.myqcloud.com/icon/gzh_bg.jpg", 
					"https://mp.weixin.qq.com/s/ivhoV24KcN1TvfViRFWFlA");
		});
	}
	
	
	/**
	 * 处理发送图文消息
	 * @param param
	 * @param title
	 * @param description
	 * @param imgUrl
	 * @param articleUrl
	 */
	private void handleNewsMsg(Map<String, String> param,String title,
		String description,String imgUrl,String articleUrl) {
		String openId = param.get("FromUserName");
		Map<String,Object> m = new HashMap<>();
		m.put("touser", openId);
		m.put("msgtype", "news");
		Map<String,Object> news = new HashMap<>();
		List<Map<String,Object>> articles = new ArrayList<>();
		news.put("articles", articles);
		Map<String,Object> article = new HashMap<>();
		article.put("title", title);
		article.put("description", description);
		article.put("url", articleUrl);
		article.put("picurl", imgUrl);
		articles.add(article);
		m.put("news", news);
		//发送推送图文消息
		String data = JSON.toJSONString(m);
		String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="
				+ getWxgzhSellhouseAcctk();
		String res = doPostSendMsg(data, url);
		log.info("发送图文消息结果:"+res);
	}
	
	

	private String getEventKeyFromScan(Map<String,String> m,boolean isFromSubscribe) {
		String ek = m.get("EventKey");
		if(isFromSubscribe)
			ek = ek.substring(8);
		return ek;
	}
	
	
	
	private void handleClickEvent(Map<String, String> param) {
		String eventKey = param.get("EventKey");
		if (StringUtils.isEmpty(eventKey)) {
			log.info("菜单点击事件推送EK值为空");
			return;
		}
		switch (eventKey) {
		case "OFFICIAL_SERVICE_QRCODE":// 官方客服二维码推送__菜单 专属客服
			sendImgMsg(param, 
					"St3wQ3ovJNuMJCYnNatEBRoNG2DhnLRItYxE03-mnow");
			break;
		default:
			log.info("未知的点击事件消息EK值:" + eventKey);
		}
	}
	
	private void sendImgMsg(Map<String, String> param,String imgId) {
		String openId = param.get("FromUserName");
		Map<String, Object> m = new HashMap<>();
		m.put("touser", openId);
		m.put("msgtype", "image");
		Map<String, Object> x = new HashMap<>();
		x.put("media_id", imgId);
		m.put("image", x);
		String json = JSON.toJSONString(m);
		String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="
				+ getWxgzhSellhouseAcctk();
		String res = doPostSendMsg(json, url);
		log.info("发送图片的结果:" + res);
	}
	

	/**
	 * 处理订阅卖房好帮手公众号消息
	 * 
	 * @param param
	 */
	private void handleSubscribeEvent(Map<String, String> param) {

		// 发送一条引导语给用户
		doSendGuideWords(param);
		//置业顾问加分
		doSellManAddScore(param);
		//判断是不是扫码进来的
		String ek = param.get("EventKey");
		if(!StringUtils.isEmpty(ek))
			handleScanEvent(param,true);
	}

	/**
	 * 给新关注的置业顾问加分
	 * @param param
	 */
	private void doSellManAddScore(Map<String, String> param) {
		
		// 执行加分,重复加分由加分模块处理。异步执行
		this.threadPool.runInThreadPool(() -> {
			// 置业顾问加分
			// 订阅卖房好帮手的置业顾问要加分，非置业顾问不做处理
			String openId = param.get("FromUserName");
			String userInfo = getWxgzhUserInfo(openId);
			JSONObject u = JSON.parseObject(userInfo);
			String unionid = u.getString("unionid");
			String nickName = u.getString("nickname");
			if (StringUtils.isEmpty(unionid)) {
				log.info("未获取到用户[" + nickName + "]的unionid");
				return;
			}
			// 查询用户信息，是否用户已经绑定了unionid
			CustomerBean customer = this.customerMapper.getUserByUnionId(unionid);
			if (customer == null) {
				log.info("用户[" + nickName + "]还没有在小程序内绑定unionId");
				return;
			}
			// 如果是置业顾问则调用加分
			String roleType = customer.getRoleType();
			if (!roleType.equals("consultant")) {
				log.info("用户[" + nickName + "]不是置业顾问,不加分");
				return;
			}
			SellManScoreBean ssb = new SellManScoreBean();
			ssb.setCreateDate(new Date());
			ssb.setCustomerId(0);
			ssb.setDate(DaysIntUtil.getDays(ssb.getCreateDate()));
			ssb.setScore(SellManScoreEnum.FOUCS_WXGZH_SELLMAN.getOnceScore());
			ssb.setScoreId(SellManScoreEnum.FOUCS_WXGZH_SELLMAN.getId());
			ssb.setScoreName("置业顾问关注卖房好帮手加分");
			ssb.setSellManCustomerId(customer.getId());
			sellManScoreService.addScoreOnFocusWxgzh(ssb);
		});
	}

	private void doSendGuideWords(Map<String, String> param) {

		this.threadPool.runInThreadPool(() -> {
			String content = "欢迎来到成都卖房帮手！\r\n" 
					+"\r\n"
					+ "置业顾问<a href=\"https://open.weixin.qq.com/connect/oauth2/authorize?"
					+ "appid=wx8aab5c1fc9f0236b&redirect_uri=https://www.fangjiadianpingbang.com/ucs/wxgzh/sell/msg/bindUserInfo"
					+ "&response_type=code&scope=snsapi_userinfo&state=x#wechat_redirect\">点击此处进行账号绑定</a>，\r\n"
					+"\r\n"
					+ "账号绑定后，可在第一时间接到客户留言通知，客户来电通知，\r\n"
					+"\r\n"
					+"确保不错过每一名客户。更多功能，戳下列菜单查看↓↓↓";
			sendTextMsg(param, content);
		});
	}
	
	
	private void sendTextMsg(Map<String, String> param,String content) {
		String openId = param.get("FromUserName");
		String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="
				+ getWxgzhSellhouseAcctk();
		Map<String, Object> m = new HashMap<>();
		m.put("touser", openId);
		m.put("msgtype", "text");
		Map<String, String> x = new HashMap<>();
		x.put("content", content);
		m.put("text", x);
		String data = JSON.toJSONString(m);
		String res = this.doPostSendMsg(data, url);
		log.info("发送文本消息结果：" + res);
	}

	private String getuserInfoUrl = "https://api.weixin.qq.com/cgi-bin/user/info?access_token="
			+ "{token}&openid={openId}&lang=zh_CN";

	private String getWxgzhUserInfo(String openId) {
		Map<String, Object> m = new HashMap<>();
		m.put("openId", openId);
		m.put("token", getWxgzhSellhouseAcctk());
		String res = this.restTemplate.getForObject(getuserInfoUrl, String.class, m);
		log.info("获取公众号用户的信息:" + res);
		return res;
	}

	/** 封装http请求发送post,返回接口的结果 */
	private String doPostSendMsg(String jsonData, String url) {
		HttpHeaders headers = new HttpHeaders();
		headers.setContentType(MediaType.APPLICATION_JSON);
		HttpEntity<String> entity = new HttpEntity<String>(jsonData, headers);
		String json = restTemplate.postForObject(url, entity, String.class);
		return json;
	}

	/**
	 * 绑定用户的unionid到本平台
	 * 
	 * @param req
	 * @return
	 */
	public int bindUserUnionId(HttpServletRequest req) {
		String code = req.getParameter("code");
		log.info("公众号授权code:" + code);
		if (StringUtils.isEmpty(code))
			return 0;
		try {
			// 换取网页授权token和公众号的openid，和上面的基础支持token不同
			JSONObject jso = getWebAuthTokenFromTct(code);
			String tk = jso.getString("access_token");
			if (StringUtils.isEmpty(tk))
				return 0;
			String openid = jso.getString("openid");
			if (StringUtils.isEmpty(openid))
				return 0;
			// 使用tk和openid调用getUserinfo接口获取unionid
			JSONObject uinfo = this.getWxgzhWebUserInfo(tk, openid);
			String unionId = uinfo.getString("unionid");
			log.info("unionid:" + unionId);
			if (StringUtils.isEmpty(unionId)) {
				log.info("未获取到公众号用户的unionid");
				return 0;
			}
			// 直接修改绑定用户表
			int x = this.customerMapper.bindUnionIdOnSellWxgzh(unionId, openid);
			if (x > 0) {
				// 绑定成功，删除置业顾问的缓存
				this.redisCacheDataService.deleteAllSellManCache();
				return 2;
			}
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			log.error("绑定用户授权异常", e);
			return 0;
		}
	}

	/** 公众号web授权获取tk接口url */
	private String wxgzhWebAcctkUrl = "https://api.weixin.qq.com/sns/oauth2/access_token"
			+ "?appid={appid}&secret={secret}&code={code}&grant_type=authorization_code";

	/**
	 * 获取网页授权的token调用凭证
	 * 
	 * @param code
	 * @return
	 */
	private JSONObject getWebAuthTokenFromTct(String code) {

		Map<String, Object> m = new HashMap<>();
		m.put("appid", WXGZH_SELL_APPID);
		m.put("secret", WXGZH_SELL_SK);
		m.put("code", code);
		String res = this.restTemplate.getForObject(this.wxgzhWebAcctkUrl, String.class, m);
		log.info("公众号web授权token信息接口结果:" + res);
		JSONObject jso = JSON.parseObject(res);
		return jso;
	}

	// 公众号获取用户信息接口地址，可获取unionid
	private String wxgzhWebGetUserInfoUrl = "https://api.weixin.qq.com/sns/userinfo"
			+ "?access_token={webacctk}&openid={openid}&lang=zh_CN";

	/**
	 * 获取微信公众号用户的unionid
	 * 
	 * @return
	 */
	private JSONObject getWxgzhWebUserInfo(String tk, String openid) {
		Map<String, Object> m = new HashMap<>();
		m.put("webacctk", tk);
		m.put("openid", openid);
		String res = this.restTemplate.getForObject(this.wxgzhWebGetUserInfoUrl, String.class, m);
		log.info("公众号web获取用户信息unionid接口结果:" + res);
		JSONObject jso = JSON.parseObject(res);
		return jso;
	}

	private String getWxgzhSellhouseAcctk() {
		String tk = this.redisCacheDataService.getWxgzhSellHouseAcctk();
		if (StringUtils.isEmpty(tk)) {
			// 初始化token
			updateGzhAcctk();
			tk = this.redisCacheDataService.getWxgzhSellHouseAcctk();
		}
		return tk;
	}

	public void updateGzhAcctk() {
		String tk = gzhAcctk();
		if (tk != null)
			this.redisCacheDataService.setWxgzhSellHouseAcctk(tk);
	}

	private String gzhAcctk() {
		String res = this.restTemplate.getForObject("https://api.weixin.qq.com/cgi-bin/token?"
				+ "grant_type=client_credential&appid=" + WXGZH_SELL_APPID + "&secret=" + WXGZH_SELL_SK, String.class);
		log.info("获取卖房好帮手微信公众号token结果:" + res);
		JSONObject jo = JSON.parseObject(res);
		String tk = jo.getString("access_token");
		if (tk != null)
			return tk;
		return null;
	}

	/**
	 * <p>
	 * 客户咨询留言的模板消息通知到指定的置业顾问 35GLThNocp9bgxLhhEgs6dPNc1eqnjXSGapV-GiR8xE
	 * 开发者调用模版消息接口时需提供模版ID 标题 客户咨询通知 行业 IT科技 - 互联网|电子商务 详细内容 {{first.DATA}}
	 * 客户姓名：{{keyword1.DATA}} 客户电话：{{keyword2.DATA}} 咨询楼盘：{{keyword3.DATA}}
	 * 咨询时间：{{keyword4.DATA}} {{remark.DATA}}
	 */
	public void sendTemplateMsgZiXunTongZhi(String openid, SellManTemplateMsg msg) {
		Map<String, Object> m = new HashMap<>();
		m.put("touser", openid);
		m.put("template_id", TEMPLATEMSG_ZIXUN_ID);
		Map<String, Object> x = new HashMap<>();
		x.put("appid", "wx4d4b24ddf6c6fb04");
		x.put("pagepath", "pages/personal/message/index/main?fromShare=true");
		m.put("miniprogram", x);
		m.put("data", getTemplateSellManData(msg));
		String data = JSON.toJSONString(m);
		String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + getWxgzhSellhouseAcctk();
		String res = this.doPostSendMsg(data, url);
		log.info("消息模板推送结果:" + res);
	}

	private Map<String, SimpleTemplateMsgBean> getTemplateSellManData(SellManTemplateMsg msg) {
		Map<String, SimpleTemplateMsgBean> data = new HashMap<>();
		data.put("first", new SimpleTemplateMsgBean("有意向客户咨询您的楼盘", "#173177"));
		data.put("keyword1", new SimpleTemplateMsgBean(msg.getFromUserName()==null?"未知":msg.getFromUserName(), "#173177"));
		data.put("keyword2",
				new SimpleTemplateMsgBean(msg.getFromUserTel() == null ? "未知" : msg.getFromUserTel(), "#173177"));
		data.put("keyword3", new SimpleTemplateMsgBean(msg.getBuildingName(), "#173177"));
		data.put("keyword4", new SimpleTemplateMsgBean(msg.getZiXunTime(), "#173177"));
		data.put("remark", new SimpleTemplateMsgBean("点击本消息跳转到买房好帮手立即回复客户咨询!", "#173177"));
		return data;
	}


	public void sendTemplateMsgCallPhone(String openId, ConsumerCallTemplateMsg msg) {
		Map<String, Object> m = new HashMap<>();
		m.put("touser", openId);
		m.put("template_id", TEMPLATE_CALL_ID);
		Map<String, Object> x = new HashMap<>();
		x.put("appid", "wx4d4b24ddf6c6fb04");
		x.put("pagepath", "pages/personal/messageReg/main");
		m.put("miniprogram", x);
		m.put("data", getTemplateCallPhone(msg));
		String data = JSON.toJSONString(m);
		String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + getWxgzhSellhouseAcctk();
		String res = this.doPostSendMsg(data, url);
		log.info("消息模板推送结果:" + res);
	}

	public void sendAddSourceMsg(String openId, Map msg) {
		Map<String, Object> m = new HashMap<>(16);
		m.put("touser", openId);
		m.put("template_id", SCORE_CHANGE);
		Map<String, Object> x = new HashMap<>(16);
		x.put("appid", "wx4d4b24ddf6c6fb04");
		x.put("pagepath", "pages/personal/integraldetail/main");
		m.put("miniprogram", x);
		m.put("data", msg);
		String data = JSON.toJSONString(m);
		log.info("公众号模板消息发送数据:{}",data);
		String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + getWxgzhSellhouseAcctk();
		String res = this.doPostSendMsg(data, url);
		log.info("加分模板消息推送结果:" + res);
	}

	private Object getTemplateCallPhone(ConsumerCallTemplateMsg msg) {
		Map<String, SimpleTemplateMsgBean> data = new HashMap<>();
		data.put("first", new SimpleTemplateMsgBean("您有一个来电，请尽快接听", "#173177"));
		data.put("keyword1", new SimpleTemplateMsgBean(msg.getPhoneNumber() ==null?"未知":msg.getPhoneNumber(), "#173177"));
		data.put("keyword2",
				new SimpleTemplateMsgBean(msg.getCallDate() == null ? "未知" : msg.getCallDate(), "#173177"));
		data.put("remark", new SimpleTemplateMsgBean("点击 【详情】 ，即可接听电话/也可直接发起呼叫", "#173177"));
		return data;
	}
}
